package com.small.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * 编码与解码
 * Created by fangzheng on 2018/1/30.
 */
public final class CodeUtils {

    /**
     * 将URL编码
     * @param source
     * @return
     */
    public static String encodeURL(String source){
        String result = null;
        try {
            result = URLEncoder.encode(source,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 将URL解码
     * @param source
     * @return
     */
    public static String decodeURL(String source){
        String result = null;
        try {
            result = URLDecoder.decode(source,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

}
